import collections


class Solution(object):
    def numberOfArithmeticSlices(self, nums):
        """
        :type nums: List[int]
        :rtype: int
        """
        n = len(nums)
        if n <= 2:
            return 0
        d = [collections.defaultdict(int) for _ in range(n)]
        total = 0
        for i in range(1, n):
            for j in range(i):
                diff = nums[i] - nums[j]
                total += d[j][diff]
                d[i][diff] += d[j][diff] + 1
        return total


data = Solution()
nums = [2, 2, 4, 6, 8]
print(data.numberOfArithmeticSlices(nums))
